import { AuditTConst } from "src/consts/audit_template_const";
import { PopupName } from "src/consts/popup_const";
import * as Api from 'src/api/net';

const state: any = {} as any;
// StateIniter.init(state, 'demo');

state.model = []
// vuex

/** 更新数据的 */
const mutations = {
    [AuditTConst.CommitBusinessList](state: any, data: any): void {
        console.log("Business_Panel data update", data);
        var arr: any = []
        if (isNoEmpty(data)) {
            for (let i = 0; i < data.length; i++) {
                arr.push(data[i].model)
            }
        }
        state.model = arr
        WLLib.panel(PopupName.AuditT_Business_Panel);
    },
}

//异步处理
const actions = {
    [AuditTConst.DispatchBusinessList](context: VuexData, data?: any): void {
        Api.AjaxPost(Config.ajaxUrl + "/audit/model/flow/list.do", data, (res: any) => {
            if (isNoEmptyObject(res.data)) {
                var list = []
                for (let i = 0; i < res.data.length; i++) {
                    if (res.data[i].model == "wanzhan_website" || res.data[i].model == "wanzhan_apply") {
                        list.push(res.data[i])
                    }
                }
                WLCommit(AuditTConst.CommitBusinessList, list);
            }
        })
    }
}

export default {
    state,
    mutations,
    actions
}